<template>
  <div>
    <div>
      <el-row type="left" justify="space-around">
        <el-col :span="6"> </el-col>
        <el-col :span="11"></el-col>
        <el-col :span="7">
          <el-button
            size="small"
            type="primary"
            @click="buffer.Bufferfrom = true"
            >添加</el-button
          ></el-col
        >
      </el-row>
      <list :mylist="mylist" @deleat="cateDela" @edit="cateEmits"></list>
      <goodsfrom
        ref="formMenu"
        :buffer="buffer"
        :cateList="cateList"
        :specsList="specsList"
        @channel="categorylist"
      ></goodsfrom>
    </div>
  </div>
</template>

<script>
import goodsfrom from "../goods/components/goodsfrom";
import list from "../goods/components/list";
export default {
  name: "",
  components: { goodsfrom, list },
  data() {
    return {
      mylist: [],
      cateList: [],
      specsList: [],
      buffer: {
        Bufferfrom: false,
      },
      pages: {
        page: 1,
        size: 20,
      },
    };
  },
  created() {},
  mounted() {
    this.categorylist();
    this.goodsLists();
    this.specslist();
  },
  methods: {
    categorylist() {
      this.$api.goodsList(this.pages).then((res) => {
        console.log(res);
        this.mylist = res.data.list;
        // console.log(this.mylist);
      });
    },
    goodsLists() {
      this.$api.cateList({ istree: true }).then((res) => {
        console.log(res);
        this.cateList = res.data.list;
        // console.log(this.mylist);
      });
    },
    specslist() {
      this.$api.specsList(this.pages).then((res) => {
        console.log(res);
        this.specsList = res.data.list;
      });
    },
    cateDela(inof) {
      let { index, row } = inof;
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          try {
            let res = await this.$api.goodsDel({ id: row.id });
            console.log("结果", res);
            this.categorylist();
          } catch {}
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    cateEmits(inof) {
      let { index, row } = inof;
    
      this.buffer.Bufferfrom = true;
        delete (row.firstcatename);
      delete (row.secondcatename);
      this.$refs.formMenu.form = JSON.parse(JSON.stringify(row));
      this.$refs.formMenu.imageUrl = "http://localhost:3000" + row.img;
      this.$refs.formMenu.form.specsattr = row.specsattr.split(",");
      this.$refs.formMenu.changeFirst(this.$refs.formMenu.form.first_cateid);
      console.log(row);
    },
  },
};
</script>
<style scoped lang="scss">
.el-row {
  margin-top: 20px;
}
</style>
